home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGNG_C / CUG187.LZH / CENTER.C < prev    next >
C/C++ Source or Header  |  1985-12-30  |  951b  |  34 lines

  1. #include "stdio.h"
  2.  
  3. /*@*****************************************************/
  4. /*@                                                    */
  5. /*@   center - center a given string on a given length.*/
  6. /*@            Trims trailing blanks before centering. */
  7. /*@                                                    */
  8. /*@    Usage:  center(string, length);                 */
  9. /*@       NOTE: The string is output to STDOUT.        */
  10. /*@                                                    */
  11. /*@*****************************************************/
  12.  
  13. center(line, linlen)
  14. int linlen;
  15. char *line;
  16. {
  17.     char *cp, *wp;
  18.     int countr, len;
  19.     char c;
  20.  
  21.     len = strlen(trim(line));    /* get non-blank length */
  22.  
  23.      /* output leading blanks */
  24.     for (countr=1; countr < (linlen - len)/2; countr++)
  25.         putc(' ', stdout);
  26.  
  27.      /* output non-blank chars */
  28.     while (c = *cp++)
  29.         putc(c, stdout);
  30.  
  31.     putc('\n', stdout);     /* end of record */
  32.  
  33. }
  34.